//
//  MAAlertView.m
//  meiang_edu
//
//  Created by 栋 on 2018/10/20.
//  Copyright © 2018年 com.meiang.meiang_edu. All rights reserved.
//

#import "MAAlertView.h"
#import "AppDelegate.h"
@interface MAAlertView()

/**
 点击确定回调
 */
@property (nonatomic ,copy) MAAlertViewBlock sureBlcok;

/**
 点击取消回调
 */
@property (nonatomic ,copy) MAAlertViewBlock cancelBlcok;

/**
 提示label
 */
@property (weak, nonatomic) IBOutlet UILabel *lblTips;


@end

@implementation MAAlertView

+ (void)showAlertViewWithMessage:(NSString *)message MakeSureBlock:(MAAlertViewBlock)makeSureblock cancelBlock:(MAAlertViewBlock)cancelBlock{
    MAAlertView * view = [[[NSBundle mainBundle] loadNibNamed:@"MAAlertView" owner:nil options:nil] lastObject];
    view.lblTips.text = message;
    view.sureBlcok = makeSureblock;
    view.cancelBlcok = cancelBlock;
    UIWindow * window = [[UIApplication sharedApplication] delegate].window;
    [window addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    [window layoutIfNeeded];
    view.alpha = 0.0;
    [view animateShow:YES];
}
- (void)animateShow:(BOOL)show{
    
    [UIView animateWithDuration:0.5 animations:^{
        if (show) {
            self.alpha = 1.0;
        }else{
            self.alpha = 0.0;
        }
    }completion:^(BOOL finished) {
        if (!show) {
            [self removeFromSuperview];
        }
    }];
}
/**
 点击确定
 */
- (IBAction)tapSure:(id)sender {
    [self animateShow:NO];
    if (_sureBlcok) {
        _sureBlcok();
    }
}

/**
 点击取消
 */
- (IBAction)tapCancel:(id)sender {
    [self animateShow:NO];
    if (_cancelBlcok) {
        _cancelBlcok();
    }
}

@end
